package com.lqg.bookLibrary.controller;

import com.lqg.bookLibrary.common.core.domain.JsonResult;
import com.lqg.bookLibrary.common.myInterface.CurrentUser;
import com.lqg.bookLibrary.common.myInterface.CurrentUserPojo;
import com.lqg.bookLibrary.pojo.Books;
import com.lqg.bookLibrary.service.recommend.BorrowedHistoryRecommend;
import com.lqg.bookLibrary.service.recommend.RateRecommend;
import com.lqg.bookLibrary.service.recommend.ThermalRecommend;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/book/recommend")
@Slf4j
@CrossOrigin
public class RecommendController {

    @Autowired
    private RateRecommend<Long, Long> rateRecommend;

    @Autowired
    private BorrowedHistoryRecommend<Long, Long> borrowedHistoryRecommend;

    @Autowired
    private ThermalRecommend thermalRecommend;

    @GetMapping("/score")
    public JsonResult recommendByScore(@CurrentUser CurrentUserPojo user) {
        log.info("为userId = {},基于评分数据推荐数据",user.getUserId());
        List<Long> recommendBooks = rateRecommend.recommendBooks(user.getUserId());
        //System.out.println("推荐的书籍为:");
        //recommendBooks.forEach(System.out::println);
        //System.out.println(recommendBooks.size());
        return JsonResult.success("success");
    }

    @GetMapping("/borrow")
    public JsonResult recommendByBorrow(@CurrentUser CurrentUserPojo user) {
        log.info("为userId = {},基于借阅数据推荐数据",user.getUserId());
        List<Long> recommendBooks = borrowedHistoryRecommend.recommendBooks(user.getUserId());
        //System.out.println("推荐的书籍为:");
        //recommendBooks.forEach(System.out::println);
        //System.out.println(recommendBooks.size());
        return JsonResult.success("success");
    }

    @GetMapping("/small")
    public JsonResult recommendSmall() {
        log.info("推荐最新最火书籍");
        List<Books> hottest = thermalRecommend.hottest();
        List<Books> latest = thermalRecommend.latest();
        latest.addAll(hottest);
        //System.out.println("推荐的书籍为:");
        //recommendBooks.forEach(System.out::println);
        return JsonResult.success("success",latest);
    }

    @GetMapping("/big")
    public JsonResult recommendBig(@CurrentUser CurrentUserPojo user) {
        log.info("为userId = {},基于借阅数据推荐数据",user.getUserId());
        List<Long> recommendBooks = borrowedHistoryRecommend.recommendBooks(user.getUserId());
        //System.out.println("推荐的书籍为:");
        //recommendBooks.forEach(System.out::println);
        //System.out.println(recommendBooks.size());
        return JsonResult.success("success");
    }

}
